/**
 * Created by Administrator on 2017/8/2.
 */
$(document).ready(function () {
    $('#uptype').click(function () {
        $('#caozuo').text("编辑分类");
        $('#czfrom').attr('action',"/yuhan/index.php/home/type/upType");
        $('#addid').append('<input type="hidden" name="typeid" id="typeid">');
        $('#typeid').val($(this).next().val());
    });
    $('#modal-form').on('blur','#typename',function () {
        checkName();
    });
    $('#modal-form').on('click','#sub',function () {
        return checkName();
    });
});
function checkName() {
    var ret = false;
    var typename=$('#typename').val();
    if (typename==''){
        $('#span1').text("类型不能为空").css('color','red');
    }else if (ishave(typename)){
        $('#span1').text("存在的分类名称").css('color','red');
    }else {
        ret=true;
        $('#span1').text("请输入分类名称").css('color','#696969');
    }
    return ret;
}
function ishave(typename) {
    var ret =false;
        $.ajax({
        url: "/yuhan/index.php/home/type/isHave",
        type: 'post',
        async: false,
        dataType: 'json',
        data: {typename: typename},
        success: function (data) {
            console.log(data);
            if (data.info == "1") {
                ret = true;
            }

        }

    });
    return ret;
}